/**
 * 
 */
package aiproject3.models;

import java.util.HashMap;

/**
 * @author Chris
 *
 */
public class Bigram implements KnowledgeBase<Character, Integer> {

	private HashMap<String, Integer> _data;
	
	private Character _lastChar;
	
	public Bigram() {
		_data = new HashMap<String, Integer>();
	}
	
	public void addToModel(Character unit) {
		// First check if there was a last char... otherwise just instantiate last char
		if (_lastChar != null) {
			if (!_data.containsKey(String.valueOf(_lastChar) + String.valueOf(unit))) {
				_data.put(String.valueOf(_lastChar) + String.valueOf(unit), 1);
			}
			else {
				_data.put(String.valueOf(_lastChar) + String.valueOf(unit), _data.get(String.valueOf(_lastChar) + String.valueOf(unit)) + 1);
			}
		}
		_lastChar = unit;
	}

	public boolean contains(Character unit) {
		if (_lastChar == null)
			return false;
		else
			return _data.containsKey(String.valueOf(_lastChar) + String.valueOf(unit));
	}	

	public Integer getValueFromModel(Character unit) {
		return _data.get(String.valueOf(_lastChar) + String.valueOf(unit));
	}

	public int getNumUnits() {
		return _data.keySet().size();
	}
	
}
